package Interfaz;
import Modelo.Step;
import java.util.Vector;

public class StepGui extends javax.swing.JDialog {
 
    private Vector steps = new Vector();
    private Step step;
    private int pos=0;
    
    public StepGui(javax.swing.JFrame parent, boolean modal, Step s) {
        super(parent, modal);
        initComponents();
        step=s;
        jBtnPrev.setVisible(false);
        jBtnNext.setVisible(false);
    }
    
    public void ViewSteps(Vector st){
        steps=st;
        jBtnOk.setVisible(false);
        jBtnPrev.setVisible(true);
        jBtnNext.setVisible(true);
        jTxtTitle.setEditable(false);
        jTxtContent.setEditable(false);
        Step step = (Step) steps.firstElement();
        try{
            jTxtTitle.setText(step.getTitle());
            jTxtContent.setText(step.getContent());
        }catch(Exception e){}
        jLblStep.setText("View Step");
    }
 
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLblStep = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTxtTitle = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTxtContent = new javax.swing.JTextArea();
        jBtnOk = new javax.swing.JButton();
        jBtnPrev = new javax.swing.JButton();
        jBtnNext = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jLblStep.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLblStep.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLblStep.setText("New Step");

        jLabel2.setText("Title:");

        jLabel3.setText("Content:");

        jTxtContent.setColumns(20);
        jTxtContent.setLineWrap(true);
        jTxtContent.setRows(5);
        jTxtContent.setWrapStyleWord(true);
        jScrollPane1.setViewportView(jTxtContent);

        jBtnOk.setText("Ok");
        jBtnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnOkActionPerformed(evt);
            }
        });

        jBtnPrev.setText("<< Prev Step");
        jBtnPrev.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnPrevActionPerformed(evt);
            }
        });

        jBtnNext.setText("Next Step >>");
        jBtnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnNextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLblStep, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                            .addComponent(jTxtTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jBtnPrev)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtnNext)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
                        .addComponent(jBtnOk)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLblStep)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTxtTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtnPrev)
                    .addComponent(jBtnNext)
                    .addComponent(jBtnOk))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnPrevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnPrevActionPerformed
        try{
            pos--;
            Step step = (Step) steps.get(pos);
            jTxtTitle.setText(step.getTitle());
            jTxtContent.setText(step.getContent());
        }catch(Exception e){}
    }//GEN-LAST:event_jBtnPrevActionPerformed

    private void jBtnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnNextActionPerformed
        try{
            pos++;
            Step step = (Step) steps.get(pos);
            jTxtTitle.setText(step.getTitle());
            jTxtContent.setText(step.getContent());
        }catch(Exception e){}
    }//GEN-LAST:event_jBtnNextActionPerformed

    private void jBtnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnOkActionPerformed
        step.setTitle(jTxtTitle.getText());
        step.setContent(jTxtContent.getText());
        dispose();
    }//GEN-LAST:event_jBtnOkActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnNext;
    private javax.swing.JButton jBtnOk;
    private javax.swing.JButton jBtnPrev;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLblStep;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTxtContent;
    private javax.swing.JTextField jTxtTitle;
    // End of variables declaration//GEN-END:variables
    
}
